﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using GameLib.Games.Components;

namespace GameLib.Games
{
    /// <summary>
    /// An abstract implementation of a generic IModMatchCollection
    /// </summary>
    /// <typeparam name="T">The IModMatcher matching the same type as the mod type specified</typeparam>
    /// <typeparam name="U">The IMod type that this Matcher matches</typeparam>
    public class AbstractModMatchCollection<T> : IModMatchCollection<T>
        where T : IMod
    {
        /// <summary>
        /// The matcher which this collection is based on
        /// </summary>
        public IModMatcher ModMatcher
        {
            get;
            protected set;
        }

        /// <summary>
        /// The mod list this matcher matched against
        /// </summary>
        public IModCollection<T> ModList
        {
            get;
            protected set;
        }

        /// <summary>
        /// The matches found by this matcher
        /// </summary>
        public IModCollection<T> Matches
        {
            get
            {
                ModCollection<T> result = new ModCollection<T>((IGame<T>)ModMatcher.Owner.Owner);
                foreach (T mod in ModMatcher.Match(ModList))
                {
                    result.Add(mod);
                }
                return result;
            }
        }
    }
}